/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainWindow.java
 *
 * Created on 2011-12-31, 14:01:24
 */
package com.elka.wdec.gui;

import com.elka.wdec.utils.Etap;
import com.elka.wdec.utils.Funkcje;
import com.elka.wdec.utils.Model;
import com.elka.wdec.utils.Rozwiazanie;
import com.elka.wdec.utils.StanPoczatkowy;

/**
 *
 * @author michal
 */
public class MainWindow extends javax.swing.JFrame
{

	/** Creates new form MainWindow */
	public MainWindow(Model model)
	{
		this.model = model;
		initComponents();
		plot1.setModel(model);
		setVisible(true);
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        input = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        majatekTrwaly = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        maxKredyt = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        iloscGotowki = new javax.swing.JFormattedTextField();
        jLabel5 = new javax.swing.JLabel();
        amortyzacja = new javax.swing.JFormattedTextField();
        jLabel6 = new javax.swing.JLabel();
        kosztyStale = new javax.swing.JFormattedTextField();
        jLabel7 = new javax.swing.JLabel();
        oprocentowanieKonta = new javax.swing.JFormattedTextField();
        jLabel8 = new javax.swing.JLabel();
        oprocentowanieKredytu = new javax.swing.JFormattedTextField();
        jLabel9 = new javax.swing.JLabel();
        stawkaPodatku = new javax.swing.JFormattedTextField();
        jLabel10 = new javax.swing.JLabel();
        niesprzedaneProcent = new javax.swing.JFormattedTextField();
        jLabel11 = new javax.swing.JLabel();
        maxProdukcja = new javax.swing.JFormattedTextField();
        start = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        numerEtapu = new javax.swing.JFormattedTextField();
        jSeparator1 = new javax.swing.JSeparator();
        output = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        plot1 = new com.elka.wdec.gui.Plot();
        jLabel17 = new javax.swing.JLabel();
        wolumen = new javax.swing.JFormattedTextField();
        jLabel18 = new javax.swing.JLabel();
        jakosc = new javax.swing.JFormattedTextField();
        jLabel19 = new javax.swing.JLabel();
        cenaSprzedazy = new javax.swing.JFormattedTextField();
        jLabel20 = new javax.swing.JLabel();
        reklamaInternetowa = new javax.swing.JFormattedTextField();
        jLabel21 = new javax.swing.JLabel();
        reklamaWPrasie = new javax.swing.JFormattedTextField();
        jLabel22 = new javax.swing.JLabel();
        reklamaTelewizyjna = new javax.swing.JFormattedTextField();
        zatwierdzEtap = new javax.swing.JButton();
        poziomRyzyka = new javax.swing.JSlider();
        jLabel4 = new javax.swing.JLabel();
        zysk = new javax.swing.JFormattedTextField();
        jLabel13 = new javax.swing.JLabel();
        kredyt = new javax.swing.JFormattedTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("WDEC - System Wspomagania Decyzji");

        jLabel1.setText("Majątek trwały firmy [zł]");

        majatekTrwaly.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        majatekTrwaly.setValue(model.getStanPoczatkowy().getMajatekTrwaly());
        majatekTrwaly.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                majatekTrwalyPropertyChange(evt);
            }
        });

        jLabel2.setText("Maksymalny kredyt [zł]");

        maxKredyt.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        maxKredyt.setValue(model.getStanPoczatkowy().getMaxKredyt());
        maxKredyt.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                maxKredytPropertyChange(evt);
            }
        });

        jLabel3.setText("Ilość gotówki [zł]");

        iloscGotowki.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        iloscGotowki.setValue(model.getStanPoczatkowy().getIloscGotowki());
        iloscGotowki.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                iloscGotowkiPropertyChange(evt);
            }
        });

        jLabel5.setText("Amortyzacja [zł]");

        amortyzacja.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        amortyzacja.setValue(StanPoczatkowy.getAmortyzacja());
        amortyzacja.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                amortyzacjaPropertyChange(evt);
            }
        });

        jLabel6.setText("Koszty stałe produktu [zł]");

        kosztyStale.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        kosztyStale.setValue(model.getStanPoczatkowy().getKosztyStale());
        kosztyStale.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                kosztyStalePropertyChange(evt);
            }
        });

        jLabel7.setText("Oprocentowanie konta bankowego [%]");

        oprocentowanieKonta.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#.##"))));
        oprocentowanieKonta.setValue(model.getStanPoczatkowy().getOprocentowanieKonta());
        oprocentowanieKonta.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                oprocentowanieKontaPropertyChange(evt);
            }
        });

        jLabel8.setText("Oprocentowanie kredytu [%]");

        oprocentowanieKredytu.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#.##"))));
        oprocentowanieKredytu.setValue(model.getStanPoczatkowy().getOprocentowanieKredytu());
        oprocentowanieKredytu.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                oprocentowanieKredytuPropertyChange(evt);
            }
        });

        jLabel9.setText("Stawka podatku [%]");

        stawkaPodatku.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#.##"))));
        stawkaPodatku.setValue(StanPoczatkowy.getPodatek());
        stawkaPodatku.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                stawkaPodatkuPropertyChange(evt);
            }
        });

        jLabel10.setText("Niesprzedane produkty kupowane za  [%]");

        niesprzedaneProcent.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#.##"))));
        niesprzedaneProcent.setValue(model.getStanPoczatkowy().getWartoscNiesprzedanych());
        niesprzedaneProcent.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                niesprzedaneProcentPropertyChange(evt);
            }
        });

        jLabel11.setText("Maksymalna zdolność produkcyjna [szt.]");

        maxProdukcja.setValue(model.getStanPoczatkowy().getMaxProdukcja());
        maxProdukcja.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                maxProdukcjaPropertyChange(evt);
            }
        });

        start.setText("START");
        start.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startActionPerformed(evt);
            }
        });

        jLabel15.setFont(jLabel15.getFont().deriveFont(jLabel15.getFont().getStyle() | java.awt.Font.BOLD, jLabel15.getFont().getSize()+4));
        jLabel15.setText("Parametry wejściowe");

        jLabel12.setText("Numer etapu");

        numerEtapu.setEditable(false);
        numerEtapu.setValue(model.getBiezacyEtap().getNumerEtapu());

        javax.swing.GroupLayout inputLayout = new javax.swing.GroupLayout(input);
        input.setLayout(inputLayout);
        inputLayout.setHorizontalGroup(
            inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15)
                    .addGroup(inputLayout.createSequentialGroup()
                        .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel12))
                        .addGap(18, 18, 18)
                        .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(majatekTrwaly, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(maxKredyt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(iloscGotowki, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(amortyzacja, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(kosztyStale, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(oprocentowanieKonta, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(oprocentowanieKredytu, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(stawkaPodatku, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(niesprzedaneProcent, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(maxProdukcja, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                            .addComponent(numerEtapu, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(start, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE))
                .addContainerGap())
        );
        inputLayout.setVerticalGroup(
            inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(majatekTrwaly, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(maxKredyt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(iloscGotowki, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(amortyzacja, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(kosztyStale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(oprocentowanieKonta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(oprocentowanieKredytu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(stawkaPodatku, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(niesprzedaneProcent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(maxProdukcja, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(inputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(numerEtapu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(start)
                .addGap(118, 118, 118))
        );

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jSeparator1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel16.setFont(jLabel16.getFont().deriveFont(jLabel16.getFont().getStyle() | java.awt.Font.BOLD, jLabel16.getFont().getSize()+4));
        jLabel16.setText("Parametry wyjściowe");

        plot1.setBackground(new java.awt.Color(254, 254, 254));
        plot1.setCursor(new java.awt.Cursor(java.awt.Cursor.CROSSHAIR_CURSOR));

        jLabel17.setText("Wolumen");

        wolumen.setEditable(false);

        jLabel18.setText("Jakość");

        jakosc.setEditable(false);

        jLabel19.setText("Cena sprzedaży");

        cenaSprzedazy.setEditable(false);

        jLabel20.setText("Reklama internetowa");

        reklamaInternetowa.setEditable(false);

        jLabel21.setText("Reklama w prasie");

        reklamaWPrasie.setEditable(false);

        jLabel22.setText("Reklama telewizyjna");

        reklamaTelewizyjna.setEditable(false);

        zatwierdzEtap.setText("ZATWIERDŹ ETAP");
        zatwierdzEtap.setEnabled(false);
        zatwierdzEtap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zatwierdzEtapActionPerformed(evt);
            }
        });

        poziomRyzyka.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                poziomRyzykaStateChanged(evt);
            }
        });

        jLabel4.setText("Zysk");

        zysk.setEditable(false);

        jLabel13.setText("Kredyt");

        kredyt.setEditable(false);

        javax.swing.GroupLayout outputLayout = new javax.swing.GroupLayout(output);
        output.setLayout(outputLayout);
        outputLayout.setHorizontalGroup(
            outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputLayout.createSequentialGroup()
                .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(outputLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(plot1, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16)
                            .addComponent(poziomRyzyka, javax.swing.GroupLayout.PREFERRED_SIZE, 599, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(outputLayout.createSequentialGroup()
                                .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel17)
                                    .addComponent(jLabel18)
                                    .addComponent(jLabel19)
                                    .addComponent(jLabel20)
                                    .addComponent(jLabel21)
                                    .addComponent(jLabel22)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(46, 46, 46)
                                .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jakosc, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(outputLayout.createSequentialGroup()
                                        .addComponent(wolumen, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(zatwierdzEtap, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(cenaSprzedazy, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(reklamaInternetowa, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(zysk, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(reklamaTelewizyjna, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(reklamaWPrasie, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
                                        .addComponent(kredyt, javax.swing.GroupLayout.Alignment.LEADING))))))
                    .addGroup(outputLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel13)))
                .addContainerGap(12, Short.MAX_VALUE))
        );
        outputLayout.setVerticalGroup(
            outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(plot1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(poziomRyzyka, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(outputLayout.createSequentialGroup()
                        .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17)
                            .addComponent(wolumen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18)
                            .addComponent(jakosc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel19)
                            .addComponent(cenaSprzedazy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel20)
                            .addComponent(reklamaInternetowa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(reklamaWPrasie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel21))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(reklamaTelewizyjna, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel22)))
                    .addComponent(zatwierdzEtap))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(outputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(outputLayout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(outputLayout.createSequentialGroup()
                        .addComponent(kredyt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(zysk, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(201, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(input, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(output, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 955, Short.MAX_VALUE)
            .addComponent(output, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(input, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(425, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void startActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_startActionPerformed
	{//GEN-HEADEREND:event_startActionPerformed
		model.generujRozwiazania();
		plot1.repaint();
		updateOutput();
		zatwierdzEtap.setEnabled(true);
	}//GEN-LAST:event_startActionPerformed

	private void majatekTrwalyPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_majatekTrwalyPropertyChange
	{//GEN-HEADEREND:event_majatekTrwalyPropertyChange
		Long val = (Long) majatekTrwaly.getValue();
		StanPoczatkowy.setMajatekTrwaly(((Long) majatekTrwaly.getValue()).longValue());
	}//GEN-LAST:event_majatekTrwalyPropertyChange

	private void zatwierdzEtapActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_zatwierdzEtapActionPerformed
	{//GEN-HEADEREND:event_zatwierdzEtapActionPerformed
		// TODO add your handling code here:
		model.nastepnyEtap(model.getNajlepszeRozwiazanie(poziomRyzyka.getValue()));
		Etap e = model.getBiezacyEtap();
		majatekTrwaly.setValue(e.getMajatekTrwaly());
		iloscGotowki.setValue(e.getIloscGotowki());
		numerEtapu.setValue(e.getNumerEtapu());
		
		model.generujRozwiazania();
		plot1.repaint();
		updateOutput();
	}//GEN-LAST:event_zatwierdzEtapActionPerformed

	private void maxKredytPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_maxKredytPropertyChange
	{//GEN-HEADEREND:event_maxKredytPropertyChange
		// TODO add your handling code here:
		StanPoczatkowy.setMaxKredyt(((Long) maxKredyt.getValue()).longValue());
	}//GEN-LAST:event_maxKredytPropertyChange

	private void iloscGotowkiPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_iloscGotowkiPropertyChange
	{//GEN-HEADEREND:event_iloscGotowkiPropertyChange
		// TODO add your handling code here:
		StanPoczatkowy.setIloscGotowki(((Long) iloscGotowki.getValue()).longValue());
	}//GEN-LAST:event_iloscGotowkiPropertyChange

	private void amortyzacjaPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_amortyzacjaPropertyChange
	{//GEN-HEADEREND:event_amortyzacjaPropertyChange
		// TODO add your handling code here:
		StanPoczatkowy.setAmortyzacja(((Long) amortyzacja.getValue()).longValue());
	}//GEN-LAST:event_amortyzacjaPropertyChange

	private void kosztyStalePropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_kosztyStalePropertyChange
	{//GEN-HEADEREND:event_kosztyStalePropertyChange
		// TODO add your handling code here:
		StanPoczatkowy.setKosztyStale(((Long) kosztyStale.getValue()).longValue());
	}//GEN-LAST:event_kosztyStalePropertyChange

	private void oprocentowanieKontaPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_oprocentowanieKontaPropertyChange
	{//GEN-HEADEREND:event_oprocentowanieKontaPropertyChange
		// TODO add your handling code here:
		StanPoczatkowy.setOprocentowanieKonta(((Double) oprocentowanieKonta.getValue()).doubleValue());
	}//GEN-LAST:event_oprocentowanieKontaPropertyChange

	private void oprocentowanieKredytuPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_oprocentowanieKredytuPropertyChange
	{//GEN-HEADEREND:event_oprocentowanieKredytuPropertyChange
		// TODO add your handling code here:
		StanPoczatkowy.setOprocentowanieKredytu(((Double) oprocentowanieKredytu.getValue()).doubleValue());
	}//GEN-LAST:event_oprocentowanieKredytuPropertyChange

	private void stawkaPodatkuPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_stawkaPodatkuPropertyChange
	{//GEN-HEADEREND:event_stawkaPodatkuPropertyChange
		// TODO add your handling code here:
		StanPoczatkowy.setPodatek(((Double) stawkaPodatku.getValue()).doubleValue());
	}//GEN-LAST:event_stawkaPodatkuPropertyChange

	private void niesprzedaneProcentPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_niesprzedaneProcentPropertyChange
	{//GEN-HEADEREND:event_niesprzedaneProcentPropertyChange
		// TODO add your handling code here:
		StanPoczatkowy.setWartoscNiesprzedanych(((Double) niesprzedaneProcent.getValue()).doubleValue());
	}//GEN-LAST:event_niesprzedaneProcentPropertyChange

	private void maxProdukcjaPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_maxProdukcjaPropertyChange
	{//GEN-HEADEREND:event_maxProdukcjaPropertyChange
		// TODO add your handling code here:
		StanPoczatkowy.setMaxProdukcja(((Long) maxProdukcja.getValue()).longValue());
	}//GEN-LAST:event_maxProdukcjaPropertyChange

	private void poziomRyzykaStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_poziomRyzykaStateChanged
	{//GEN-HEADEREND:event_poziomRyzykaStateChanged
		// TODO add your handling code here:
		int ryzyko = (int) poziomRyzyka.getValue();
		plot1.updateRyzyko(ryzyko);
		plot1.repaint();
		updateOutput();
	}//GEN-LAST:event_poziomRyzykaStateChanged
	
	private void updateOutput()
	{
		Rozwiazanie r = model.getNajlepszeRozwiazanie(poziomRyzyka.getValue());
		if (r == null)
		{
			return;
		}
		wolumen.setValue(r.getWolumen());
		jakosc.setValue(r.getJakosc());
		cenaSprzedazy.setValue(r.getCena());
		int reklama = (int)r.getReklama();
                int[] podzialReklamy = Funkcje.pieniadzeNaReklame(reklama);
                reklamaInternetowa.setValue(podzialReklamy[1]);
                reklamaTelewizyjna.setValue(podzialReklamy[0]);
                reklamaWPrasie.setValue(podzialReklamy[2]);
		kredyt.setValue(r.getKredyt());
		zysk.setValue(r.getZysk());
	}
	
	public void run()
	{
		while (true)
		{
			
		}
	}
	Model model;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField amortyzacja;
    private javax.swing.JFormattedTextField cenaSprzedazy;
    private javax.swing.JFormattedTextField iloscGotowki;
    private javax.swing.JPanel input;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JFormattedTextField jakosc;
    private javax.swing.JFormattedTextField kosztyStale;
    private javax.swing.JFormattedTextField kredyt;
    private javax.swing.JFormattedTextField majatekTrwaly;
    private javax.swing.JFormattedTextField maxKredyt;
    private javax.swing.JFormattedTextField maxProdukcja;
    private javax.swing.JFormattedTextField niesprzedaneProcent;
    private javax.swing.JFormattedTextField numerEtapu;
    private javax.swing.JFormattedTextField oprocentowanieKonta;
    private javax.swing.JFormattedTextField oprocentowanieKredytu;
    private javax.swing.JPanel output;
    private com.elka.wdec.gui.Plot plot1;
    private javax.swing.JSlider poziomRyzyka;
    private javax.swing.JFormattedTextField reklamaInternetowa;
    private javax.swing.JFormattedTextField reklamaTelewizyjna;
    private javax.swing.JFormattedTextField reklamaWPrasie;
    private javax.swing.JButton start;
    private javax.swing.JFormattedTextField stawkaPodatku;
    private javax.swing.JFormattedTextField wolumen;
    private javax.swing.JButton zatwierdzEtap;
    private javax.swing.JFormattedTextField zysk;
    // End of variables declaration//GEN-END:variables
}
